﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WCFService;
using Database;

namespace DataAccessLayer
{
    public class ThreadData
    {
        public int ForumID { get; set; }
        public int SubForumID { get; set; }
        public int ID { get; set; }
        public String Title { get; set; }
        public String body { get; set; }
        //public String Manager { get; set; }
    }

    public class SubForumDataLayer
    {
        public static List<ThreadData> GetSubForumData(int forumID, int subForumID)
        {
            List<ThreadData> tdList = new List<ThreadData>();

            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
            LogicForumImp forumManager = new LogicForumImp();
            SubForum subForumDataObj = forumManager.getSubForum(null, forumID, subForumID);

            SortedDictionary<int, Thread> threads = subForumDataObj.getThreads();

            foreach (Thread t in threads.Values)
            {
                tdList.Add(new ThreadData { ForumID = t.getForumId(), SubForumID = t.getSubForumId(), ID = t.getId(), Title = t.getTitle(), body = t.getBody() });
            }

            return tdList;
        }

        public static String GetTitle(int forumID, int subForumID)
        {
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
            LogicForumImp forumManager = new LogicForumImp();
            return forumManager.getSubForum(null, forumID, subForumID).getTitle();
        }

        public static List<String> GetSubForumDetails(int forumID, int subForumID)
        {
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
            LogicForumImp forumManager = new LogicForumImp();
            SubForum subForum = forumManager.getSubForum(null, forumID, subForumID);
            List<String> subForumDetails = new List<String>();
            subForumDetails.Add(subForum.getTitle());
            subForumDetails.Add(subForum.SFModeratorsToString());
            subForumDetails.Add(forumManager.getForum(null,subForum.getForumId()).getTitle());
            return subForumDetails;
        }
    }
}